package com.wkhyapp.lm.view;

import android.graphics.Color;
import android.os.Build;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.loadmore.LoadMoreView;
import com.wkhyapp.lm.R;
import com.wkhyapp.lm.adapter.MarketaAdapter;
import com.wkhyapp.lm.adapter.NoticeAdapter;
import com.wkhyapp.lm.base.SuperActivity;
import com.wkhyapp.lm.contract.MarketPresenter;
import com.wkhyapp.lm.contract.MarketView;
import com.wkhyapp.lm.http.vo.Market;
import com.wkhyapp.lm.http.vo.Notice;
import com.wkhyapp.lm.utils.StatusBarFontUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MarketActivity extends SuperActivity<MarketPresenter> implements MarketView {



    @BindView(R.id.refresh_view)
    SwipeRefreshLayout refresh_view;
    @BindView(R.id.recycler_view)
    RecyclerView recycler_view;
    private MarketaAdapter marketaAdapter;
    private List<Market> markets;
    @BindView(R.id.back_iv)
    ImageView back_iv;
    @Override
    public void initUI() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            translucentStatusBar();
        }
        StatusBarFontUtil.setLightStatusBarColor(this);


        markets = new ArrayList<>();
        marketaAdapter = new MarketaAdapter(R.layout.item_market,markets);
        refresh_view.setColorSchemeColors(Color.parseColor("#FFEC48"),Color.parseColor("#FFEC48"));
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recycler_view.setLayoutManager(manager);
        recycler_view.setAdapter(marketaAdapter);
        refresh_view.setRefreshing(false);
        mPresenter.getData();
    }

    @Override
    protected void initListener() {
        marketaAdapter.setLoadMoreView(new LoadMoreView() {
            @Override
            public int getLayoutId() {
                return R.layout.view_index_load_more;
            }

            @Override
            protected int getLoadingViewId() {
                return com.chad.library.R.id.load_more_loading_view;
            }
            @Override
            protected int getLoadFailViewId() {
                return com.chad.library.R.id.load_more_load_fail_view;
            }
            @Override
            protected int getLoadEndViewId() {
                return com.chad.library.R.id.load_more_load_end_view;
            }
        });

        marketaAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                marketaAdapter.loadMoreComplete();
                marketaAdapter.loadMoreEnd();

            }
        });
        refresh_view.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPresenter.getData();
            }
        });


        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void setMarket(List<Market> list) {
        markets.clear();
        if(list!=null&&list.size()>0){
            markets.addAll(list);
        }
        marketaAdapter.notifyDataSetChanged();
        refresh_view.setRefreshing(false);
        marketaAdapter.loadMoreComplete();
    }

    @Override
    protected void afterCreate() {

    }

    @Override
    protected MarketPresenter createPresenter() {
        return mPresenter = new MarketPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_market;
    }



}
